//
//  MyMoveCardBtnV.m
//  carcareIOS
//
//  Created by 王然 on 16/9/19.
//  Copyright © 2016年 chezheng. All rights reserved.
//

#import "MineMoveCardBtnV.h"

@implementation MineMoveCardBtnV

- (instancetype)initWithOrigin:(CGPoint)origin
{
    self = [super initWithFrame:CGRectMake(origin.x, origin.y, __MAIN_WIDTH, Bottom_BtnV_Height)];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self createUI];
    }
    return self;
}
- (void)createUI
{
    CGFloat iconY = 29 * __MAIN_RATIO_375;
    CGFloat iconX = 30 * __MAIN_RATIO_375;
    CGFloat iconAndIconX = 59 * __MAIN_RATIO_375;
    CGFloat iconW = (__MAIN_WIDTH - iconX * 2 - iconAndIconX * 3) / 4;
    
    NSArray * iconNames = @[@"moveCarDelete",@"moveCarChangeStyle",@"moveCarEditInfo",@"MoveCarSave"];
    NSArray * texts = @[@"删除",@"更换样式",@"编辑信息",@"保存"];
     __weak __typeof(self) wself = self;
    CGFloat bottomLY = 0;
    for (int index = 0 ; index < iconNames.count; index ++) {
        UIImage * iconImage = ImageNamed(iconNames[index]);
        UIButton * btn =[MineMoveCardBtnV text:texts[index] iconName:iconNames[index] index:index onView:self frame:CGRectMake(iconX + (iconW + iconAndIconX) * index, iconY, iconW, iconW * iconImage.size.height / iconImage.size.width + 12 * __MAIN_RATIO_375 + 19)click:^(NSInteger index) {
            if (wself.btnClick)wself.btnClick(index);
        }];
        bottomLY = btn.bottom + 39 * __MAIN_RATIO_375;
    }
    
    //挪车卡使用说明
    CGFloat tipsBtnH = 19;
    UIButton * tipsBtn = [[UIButton buttonWithFrame:CGRectMake(iconX,bottomLY, __MAIN_WIDTH - iconX, tipsBtnH) title:@"" textColor:[UIColor clearColor] font:FONT_DEFAULT_Light(13) click:^{
        if(wself.moveCarTipClick)wself.moveCarTipClick();
    }] setupOnView:self];
    NSString * tipsStr = [NSString stringWithFormat:@"挪车使用说明"];
    NSMutableAttributedString * tipsAttributeStr = [[NSMutableAttributedString alloc]initWithString:tipsStr];
    NSRange tipsRange = NSMakeRange(0, [tipsStr length]);
    [tipsAttributeStr addAttribute:NSForegroundColorAttributeName value:COLOR_HEXSTRING(@"#1F90E5") range:tipsRange];
    [tipsAttributeStr addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:tipsRange];
    [tipsBtn setAttributedTitle:tipsAttributeStr forState:UIControlStateNormal];
}
+ (UIButton *)text:(NSString *)text iconName:(NSString *)iconName index:(NSInteger)index onView:(UIView *)view frame:(CGRect)frame click:(void(^)(NSInteger index))click
{
    UIImage * iconImage = ImageNamed(iconName);
    if(!iconName)return nil;
    UIImageView * iconV = [[UIImageView imageViewWithFrame:CGRectMake(frame.origin.x,frame.origin.y,frame.size.width, frame.size.width * iconImage.size.height / iconImage.size.width) image:iconImage] setupOnView:view];
    UILabel * label =[[[UILabel labelWithFrame:CGRectMake(0, frame.origin.y + frame.size.height - 19, iconV.size.width * 2, 19) font:FONT_DEFAULT_Light(12) text:text textColor:COLOR_HEXSTRING(@"#999999")] setupOnView:view] labelResetTextAlignment:NSTextAlignmentCenter];
    [label setCenterX:iconV.left + iconV.width / 2];
    UIButton * btn = [[UIButton buttonEmptyWithFrame:frame click:^{
        if(click)click(index);
    }] setupOnView:view];
    //btn.backgroundColor = [[UIColor redColor] colorWithAlphaComponent:0.4];
    return btn;
}
@end
